<template>
<el-container>
  <el-header style="height: auto;">
    <el-form>
      <el-row class="back">
        <el-col>
          <el-button @click="toBack" size="small" type="primary">返回</el-button>
        </el-col>
      </el-row>
      <el-row>
        <el-col :xl="{ span: 4 }" :lg="{ span: 4 }">
          <el-form-item label="累积已用" label-width="80px">
            <el-input size="small" v-model="cardFlowActUsed" style="width: 100%;"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="{ span: 4 }" :lg="{ span: 4 }">
          <el-form-item label="累积剩余" label-width="80px">
            <el-input size="small" v-model="carFlowSurplus" style="width: 100%;"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </el-header>
  <el-main style="height: auto;">
    <el-table :header-cell-style="{ 'background':$store.state.app.tableBgColor,'color':'#606266' }" :data="tableData" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange" v-loading.fullscreen="tableLoading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.2)">
      <el-table-column type="selection" align="center"></el-table-column>
      <el-table-column prop="cardNumber" label="业务号码" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="toUsage">{{ scope.row.cardNumber }}</el-button>
        </template>
      </el-table-column><!--el-table-column(-->
<!--prop="dictAgentTypeName"-->
<!--label="所属流量池"-->
<!--align="center")-->
      <el-table-column prop="dictChannelCardStatus" label="卡状态" align="center"></el-table-column>
      <el-table-column prop="cumulativeFlow" label="总用量（实际）" align="center"></el-table-column>
      <el-table-column prop="curentFlowForMonthU" label="当月用量（实际）" align="center"></el-table-column>
      <el-table-column prop="cardUse" label="卡用途" align="center"></el-table-column>
    </el-table>
    <div class="block"><span class="demonstration"></span>
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-size="pageSize" layout="prev, pager, next, jumper" :page-count="maxPage" :hide-on-single-page="value" background></el-pagination>
    </div>
  </el-main>
</el-container>
</template>

<script>
import { viewprimaryFlowPoolSubordinateCard } from '@/api/getData'

export default {
  name: 'CardList',
  data() {
    return {
      maxPage: 1,
      tableData: [],
      pageSize: 10,
      currentPage: 1,
      ascs: [],
      descs: [],
      multipleSelection: [],
      tableLoading: false,
      cardFlowActUsed: '',
      carFlowSurplus: '',
      value: false,
      cardNumber: '',
      dictChannelRequestStatus: '',
      cumulativeFlow: '',
      cardUse: '',
      firstPoolFlowId: '',
      active:'',
    }
  },
  created() {
    this.firstPoolFlowId = this.$route.params.id
    this.active = this.$route.params.active
    if(this.active == "null"){
      this.active = ''
    }
    this.initData()
  },
  methods: {
    async initData() {
      const returnData = await viewprimaryFlowPoolSubordinateCard({
        firstPoolFlowId: this.firstPoolFlowId,
        dictChannelCardStatus:this.active,
        page: {
          current: this.currentPage + '',
          size: this.pageSize + '',
          ascs: this.ascs,
          descs: this.descs
        }
      },
      {
        obj: this,
        key: 'tableLoading'
      })
      this.tableData = []
      if (returnData._result) {
        this.maxPage = Math.ceil(returnData.data.total / this.pageSize) // 分页的最大页数
        // 数据回显
        returnData.data.records.map(item => {
          const obj = {}
          obj.id = item.id
          obj.cumulativeFlow = item.cumulativeFlow // 累积已用
          obj.carFlowSurplus = item.carFlowSurplus // 累积剩余
          obj.cardNumber = item.cardNumber // 业务号码
          obj.dictChannelCardStatus = item.dictChannelCardStatusName // 卡状态
          obj.curentFlowForMonthU = item.curentFlowForMonthU // 当月使用（实际）
          obj.cardUse = item.cardUse // 卡用途
          this.tableData.push(obj)
        })
        this.tableLoading = false
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleSizeChange(val) {
      //console.log(`每页 ${val} 条`)
      this.pageSize = val
    },
    handleCurrentChange(val) {
      //console.log(`当前页: ${val}`)
      this.currentPage = val
      this.initData()
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => {})
    },
    toUsage() {
      this.$router.push({ path: '/package/usage' })
    },
    toBack() {
      this.$router.back(-1);
    }
  }
}
</script>

<style scoped lang="scss">
.el-container {
  .el-header {
    margin-top: 5vh;
    .back {
      margin-bottom: 3vh;
    }
  }
  .el-main {
    .block {
      float: right;
    }
  }
}
</style>
